package com.example.lisongyu;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity4 extends AppCompatActivity {
private ListView id_lv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main4);
        id_lv=findViewById(R.id.id_lv);

        String[] strings = {"张三","李四","翔神","曹神","J神"};

        ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>
                (this,android.R.layout.simple_expandable_list_item_1,strings);


       id_lv.setAdapter(arrayAdapter);

      id_lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
              Toast.makeText(MainActivity4.this,"你选择了"+i,Toast.LENGTH_SHORT).show();
          }
      });

    }
}
